package com.tianma315.admin.material.service.impl;

import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.tianma315.admin.common.base.CoreServiceImpl;
import com.tianma315.admin.material.VO.MaterialAndTemplateVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.tianma315.admin.material.dao.MaterialDao;
import com.tianma315.admin.material.domain.MaterialDO;
import com.tianma315.admin.material.service.MaterialService;

import java.util.List;

/**
 * 
 * <pre>
 * 原材料
 * </pre>
 * <small> 2019-05-25 15:23:18 | Aron</small>
 */
@Service
public class MaterialServiceImpl extends CoreServiceImpl<MaterialDao, MaterialDO> implements MaterialService {

    @Autowired
    private MaterialDao materialDao;

    @Override
    public Page<MaterialAndTemplateVO> getMaterialAndTemplateVOPage(Integer pageNumber, Integer pageSize, MaterialDO materialDTO) {
         Page<MaterialAndTemplateVO> page = new Page<>(pageNumber,pageSize);
         List<MaterialAndTemplateVO> materialAndTemplateVOList = materialDao.getMaterialAndTemplateVOPage(page,materialDTO);
//         page.setTotal(materialAndTemplateVOList.size());
         page.setRecords(materialAndTemplateVOList);
        return page;
    }

    @Override
    public Boolean addMaterialAndTemplate(MaterialDO materialDO) {
        materialDO.setState(0);
        return insert(materialDO);
    }

    @Override
    public Boolean deleteMaterial(Integer id) {
        MaterialDO materialDO = new MaterialDO();
        materialDO.setState(1);
        materialDO.setMaterialId(id);
        return updateById(materialDO);
    }

    @Override
    public List<MaterialDO> getMaterialList() {
        EntityWrapper<MaterialDO> wrapper = new EntityWrapper<>();
        wrapper.eq("state", 0);
        List<MaterialDO> materialDOS = selectList(wrapper);
        return materialDOS;
    }
}
